﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.IdentityModel.Logging;
using Project.Yan.Net.Models;

namespace Project.Yan.Net.Filters
{
    public class ApiResultAttribute: ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            base.OnActionExecuted(context);
            if (context.Result is not JsonResult)
            {
                var objectResult = context.Result as ObjectResult;
                context.Result = new OkObjectResult(ApiResponse<object>.Success(objectResult != null ? objectResult.Value : objectResult));
            }
        }
    }
}
